new Vue({
	el: '#app',
	data: {
		uid: '',
		api_token: '',
		page: '1',
		t: [],
		list: [],
		thumb_path: '',
		isShow: false,
		loadingId: ''
	},
	mounted: function() {
		console.log("mounted end");
		this.uid = $api.getStorage('uid');
		this.api_token = $api.getStorage('api_token');
		this.init();
	},
	methods: {
		init: function() {
			var self = this;
			//			self.getList();
			apiready = function() {
				//loading动画加载
				self.isS();
				//滚动到底部加载更多
				api.addEventListener({
					name: 'scrolltobottom',
					extra: {
						threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
					}
				}, function(ret, err) {
					//alert('已滚动到底部');
					self.page++;
					if(self.page > self.pageCount) {
						api.toast({
							msg: '没有更多了',
							duration: 1000,
							location: 'bottom'
						});
					} else {
						self.getList();
					}
				});
			};
		},
		isS: function() {
			var self = this;
			var UILoading = api.require('UILoading');
			if(self.isShow) {
				console.log(self.loadingId);
				UILoading.closeFlower({
					id: self.loadingId
				});
			} else {
				UILoading.flower({
					center: {
						x: api.winWidth / 2.0,
						y: api.winHeight / 2.0
					},
					size: 30,
					fixed: true
				}, function(ret) {
					console.log(JSON.stringify(ret));
					self.loadingId = ret.id;
				});
				self.getList();
			}
		},
		//课程列表
		getList: function() {
			var self = this;
			var data = {
				uid: self.uid,
				token: self.api_token,
				page: self.page
			};
			$.post(base + config.study_my_lesson, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.t = msg.data;
					for(var i = 0; i < self.t.length; i++) {
						self.list.push(self.t[i]);
					};
					self.pageCount = msg.page_count;
					self.thumb_path = msg.thumb_path;
					self.isShow = true;
					self.isS();
				} else {
					self.isShow = true;
					self.isS();
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//跳转到课程评分
		jumpProductMsg: function(id) {
			api.openWin({
				name: 'previousClasses',
				url: 'previousClasses.html',
				reload: true,
				vScrollBarEnabled: false,
				pageParam: {
					id: id
				}
			});
		},
		//关闭本页面
		close: function() {
			api.closeWin();
		},
	}
})